/*
 * @Company: TWL
 * @Author: xue jian
 * @Email: xuejian@kanzhun.com
 * @Date: 2019-11-21 21:14:49
 */
#include "cityhash/src/city.h"
#include <fstream>
#include <sstream>
#include <unordered_map>
#include <iostream>
#include <vector>
#include <string>
#include "nlohmann/json.hpp"
using json = nlohmann::json;
int main() {
    std::ifstream infile("fids_file");
    std::ifstream infile2("fids_file2");
    std::ifstream infile_data("data_file");
    std::vector<std::string> fea_index({"boss_l1code", "boss_l2code", "boss_position", "boss_combine_code", "boss_city", "geek_position", "geek_city", "geek_combine_code", "boss_id", "job_id", "geek_id", "exp_id", "page", "rank", "list_time", "deal_time", "lid", "pk_class", "sessionid", "deal_type", "jl", "jh", "job_workyears", "job_degree", "geek_gender", "geek_degree", "geek_school_level", "geek_cmp_level", "geek_apply_status", "geek_workyears", "el", "eh", "b2g_degree_match", "b2g_degree_rel_match", "b2g_salary_match", "b2g_salary_rel_match", "b2g_workyears_match", "b2g_workyears_rel_match", "b2g_static_match", "b2g_static_rel_match", "geek_chat_s2_num_1d7", "b2g_skill_match", "b2g_w2v_pref_gof", "b2g_w2v_orig_gof", "b2g_pastpos_addf_rate", "b2g_school_level_gof", "b2g_school_type1_gof", "b2g_school_type2_gof", "b2g_fresh_graduate_gof", "b2g_degree_gof", "b2g_gender_gof", "b2g_apply_status_gof", "geek_min_active_tdiff", "geek_min_chat_tdiff", "exp_det_num_24h", "exp_pas_addf_num_24h", "b2g_salary_gof", "b2g_workyears_gof", "b2g_cmp_level_gof", "b2g_pos_major_match", "b2g_pos_workyears_major_match", "b2g_pos_skill_match", "b2g_position_similarity", "boss_cmp_level", "b2g_overseas_match", "job_overseas_tag", "geek_overseas_tag", "b2g_resp_workyears_gof", "b2g_resp_school_level_gof", "g2b_cmp_level_gof", "g2b_degree_gof", "g2b_salary_gof", "g2b_workyears_gof", "g2b_scale_gof", "g2b_stage_gof", "g2b_title_type_gof", "exp_register_tdiff", "geek_complete_tdiff", "b2g_title_w2v_orig_gof", "b2g_major_w2v_gof", "b2g_school_w2v_gof", "b2g_work_distance", "geek_workdist_sensi", "b2g_company_gof", "exp_f1_pas_cp_addf_rate_1d7", "geek_simpos_workyears", "geek_degree_new", "boss_title_type", "g2b_w2v_pref_gof", "g2b_w2v_orig_gof", "b2g_cdssm_gof", "b2g_pjenn_gof", "exp_min_active_tdiff", "b2g_pos_pastpos_similarity", "b2g_age_gof", "b2g_position_gof", "b2g_pos_similarity", "b2g_position_addf_rate", "g2b_position_addf_rate", "b2g_city_addf_rate", "job_plist_times_14d", "job_addfchat_times_7d", "job_success_times_7d", "job_det_times_7d", "job_addf_pchat_times_7d", "job_addf_success_times_7d", "job_addf_times_7d", "job_addfchat_times_2d", "job_success_times_2d", "job_det_times_2d", "job_addf_pchat_times_2d", "job_addf_success_times_2d", "job_addf_times_2d", "job_pdet_times_14d", "job_paddf_times_14d", "job_paddfchat_times_7d", "job_psuccess_times_7d", "job_pdet_times_7d", "job_paddf_pchat_times_7d", "job_paddf_success_times_7d", "job_paddf_times_7d", "job_paddfchat_times_2d", "job_psuccess_times_2d", "job_pdet_times_2d", "job_paddf_pchat_times_2d", "job_paddf_success_times_2d", "boss_addfchat_times_2d", "boss_det_times_2d", "boss_addf_pchat_times_2d", "boss_addf_success_times_2d", "boss_addf_times_2d", "boss_paddfchat_times_2d", "boss_psuccess_times_2d", "boss_pdet_times_2d", "boss_paddf_pchat_times_2d", "boss_paddf_success_times_2d", "job_paddf_times_2d", "boss_paddf_times_2d", "geek_plist_times_14d", "geek_addfchat_times_7d", "geek_success_times_7d", "geek_det_times_7d", "geek_addf_pchat_times_7d", "geek_addf_success_times_7d", "geek_addf_times_7d", "geek_addfchat_times_2d", "geek_success_times_2d", "geek_det_times_2d", "geek_addf_pchat_times_2d", "geek_addf_success_times_2d", "geek_addf_times_2d", "geek_pdet_times_14d", "geek_paddf_times_14d", "geek_paddfchat_times_7d", "geek_psuccess_times_7d", "geek_pdet_times_7d", "geek_paddf_pchat_times_7d", "geek_paddf_success_times_7d", "geek_paddf_times_7d", "geek_paddfchat_times_2d", "geek_psuccess_times_2d", "geek_pdet_times_2d", "geek_paddf_pchat_times_2d", "geek_paddf_success_times_2d", "geek_paddf_times_2d", "boss_view_geek_14d", "boss_det_geek_14d", "boss_pview_geek_14d", "boss_pdet_geek_14d", "geek_addfchat_rate_2d", "geek_success_rate_2d", "geek_addf_pchat_rate_2d", "geek_addf_success_rate_2d", "geek_addf_rate_2d", "geek_paddfchat_rate_2d", "geek_psuccess_rate_2d", "geek_paddf_pchat_rate_2d", "geek_paddf_success_rate_2d", "geek_paddf_rate_2d", "geek_addfchat_rate_7d", "geek_success_rate_7d", "geek_addf_pchat_rate_7d", "geek_addf_success_rate_7d", "geek_addf_rate_7d", "geek_paddfchat_rate_7d", "geek_psuccess_rate_7d", "geek_paddf_pchat_rate_7d", "geek_paddf_success_rate_7d", "geek_paddf_rate_7d", "geek_pdet_rate_14d", "geek_paddf_rate_14d", "job_addfchat_rate_2d", "job_success_rate_2d", "job_addf_pchat_rate_2d", "job_addf_success_rate_2d", "job_addf_rate_2d", "job_paddfchat_rate_2d", "job_psuccess_rate_2d", "job_paddf_pchat_rate_2d", "job_paddf_success_rate_2d", "job_paddf_rate_2d", "job_addfchat_rate_7d", "job_success_rate_7d", "job_addf_pchat_rate_7d", "job_addf_success_rate_7d", "job_addf_rate_7d", "job_paddfchat_rate_7d", "job_psuccess_rate_7d", "job_paddf_pchat_rate_7d", "job_paddf_success_rate_7d", "job_paddf_rate_7d", "job_pdet_rate_14d", "job_paddf_rate_14d", "boss_addfchat_rate_2d", "boss_addf_pchat_rate_2d", "boss_addf_success_rate_2d", "boss_addf_rate_2d", "boss_paddfchat_rate_2d", "boss_psuccess_rate_2d", "boss_paddf_pchat_rate_2d", "boss_paddf_success_rate_2d", "boss_paddf_rate_2d", "b2g_airbnb_emb_gof_int", "geek_fresh_graduate", "geek_work_p", "geek_school_type1", "geek_school_type2", "geek_major", "geek_rev_work_year", "geek_business_code", "geek_job_hopping", "geek_school_ids", "boss_company", "boss_bussiness_id", "boss_district_code", "boss_comp_industry", "boss_comp_scale", "boss_comp_stage", "boss_subway_line_id", "boss_subway_station_id", "b2g_workyears_recent10", "b2g_cmp_level_recent10", "b2g_school_level_recent10", "b2g_school_type1_recent10", "b2g_school_type2_recent10", "b2g_degree_recent10", "b2g_gender_recent10", "b2g_apply_status_recent10", "b2g_salary_recent10", "boss_addf_geek_recent10", "boss_addf_expect_recent10", "job_addf_geek_recent10", "job_addf_expect_recent10", "boss_success_geek_recent10", "platform", "day_of_week"});
    std::unordered_map<std::string, int> map_fea_index;
    int count(0);
    for (auto& s:fea_index) {
        map_fea_index.insert(std::make_pair(s, count++));
    }
    std::unordered_map<int, int> slot_index;
    std::ifstream fea("nn_galaxy.fea");
    json fea_slot;
    fea>>fea_slot;
    fea.close();

    for (auto&el:fea_slot.items()) {
        if (el.key() == "hour_of_day" || el.key() == "day_of_week") {
            continue;
        }
        slot_index.insert(std::make_pair(el.value().at("slot").get<int>(), map_fea_index.at(el.key())));
    }
    std::ofstream outfile("bug_terms");
    while (!infile.eof()) {
        std::string predict_str;
        std::string transfer_str;
        std::string data_str;

        getline(infile, predict_str);
        getline(infile2, transfer_str);
        getline(infile_data, data_str);
        std::stringstream ss(transfer_str);
        std::string fid;
        std::unordered_map<int64_t, int> fids_map;
        while (getline(ss, fid, '\t')) {
            fids_map.insert(std::make_pair(std::stoll(fid), 0));
        }
        std::stringstream ss_data(data_str);
        std::vector<std::string> fea_cont;
        while(getline(ss_data, fid, '\t')) {
            fea_cont.push_back(fid);
        }

        std::stringstream ss_predict(predict_str);
        
        while (getline(ss_predict, fid, '\t')) {
            auto it = fids_map.find(std::stoll(fid));
            if (it == fids_map.end()) {
                int slot = get_slot(std::stoll(fid));
                if (slot == 74||slot == 73) {
                    continue;
                }
                std::cout.precision(10);
                std::cout<<slot<<std::endl;
                std::cout<<"the slot is "<<slot<<"\t the content is "<<fea_cont.at(slot_index.at(slot))
                <<"\t the predict fid is "<<fid<<'\t';
                for (auto&fid_map:fids_map) {
                    if (get_slot(fid_map.first) == slot) {
                        std::cout<<"the transfer fid is "<<fid_map.first<<std::endl;
                    }
                }
                for (int i(0); i<20; ++i)
                std::cout<<"The real fid should be "<<get_fid(std::to_string(i), slot)<<std::endl;
                outfile<<data_str<<std::endl;
            }
        }
        std::cout<<"==========="<<std::endl;
        // exit(true);
    }
    outfile.close();
    infile.close();
    infile2.close();
    infile_data.close();
}